package com.zjuee.web.ledger.controller;

import com.zjuee.base.bean.response.R;
import com.zjuee.base.constant.Common;
import com.zjuee.base.dto.common.login.LoginDto;
import com.zjuee.base.valid.Insert;
import com.zjuee.base.valid.Update;
import com.zjuee.service.PlanRegimeService;
import com.zjuee.service.PlanService;
import com.zjuee.base.model.common.plan.PlanRegime;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping(Common.Service.ZJUEE_CO_MAIN_PLAN_URL_PREFIX)
public class PlanRegimeController {

    @Resource
    private PlanRegimeService planRegimeService;
    @Resource
    private PlanService planService;
    @Resource
    private LoginDto loginDto;

    @PostMapping("/regime/add")
    public R<Long> addPlanRegime(@Validated(Insert.class) @RequestBody PlanRegime planRegime) {
        if (planRegime.getWpiId() == null) {
            return R.fail("计划ID为空！");
        }
        return R.ok(planRegimeService.add(planRegime));
    }

    @PutMapping("/regime/update")
    public R<Boolean> updatePlanRegime(@Validated(Update.class) @RequestBody  PlanRegime planRegime) {
        if (planRegime.getWpiId() == null) {
            return R.fail("计划ID为空！");
        }
        return R.ok(planRegimeService.update(planRegime));
    }

//     
//    public R<Boolean> deletePlanRegime(@NotNull Long id, @NotNull String wpiYear) {
//        Boolean type = false;
//        if (wpiYear.equals(DateUtils.getYear(new Date()))) {
//            type = planRegimeService.delete(id, loginDto.getPlanId());
//        } else {
//            PlanInfo plan = planService.selectInfoByBciId(loginDto.getOrgBusinessId(), wpiYear);
//            if (plan != null) {
//                type = planRegimeService.delete(id, plan.getId());
//            } else {
//                return R.fail("删除计划制度信息失败");
//            }
//        }
//        if (type) {
//            return R.ok("success");
//        }
//        return R.fail("删除计划制度信息失败");
//    }
}
